import{CodeToText} from 'element-china-area-data'

const changeUtils ={
    changeData(user){
        let updateUser = JSON.parse(JSON.stringify(user))
        if(user.ismarid === '已婚'){
            updateUser.ismarid = 1
        }else if (user.ismarid === '未婚'){
            updateUser.ismarid = 0
        }else{
            updateUser.ismarid = -1
        }

        let fixAddr = ''
        if(user.address!==null||true){
            user.address.forEach(value=>{
                fixAddr += CodeToText[value]
            })

            updateUser.address = fixAddr
        }
        else{
            user.address = ''
        }

        let today = new Date()
        let birthday = Date.parse(user.birth)

        let diff = Math.abs(today - birthday)
        let res = Math.floor(diff/(1000*3600*24))
        res = res / 365
        user.age = Math.round(res)

        return updateUser
    }
}

export default changeUtils